package com.example.orderservice.controller;

import com.example.orderservice.feign.StockClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class OrderController {
    private final StockClient stockClient;

    public OrderController(StockClient stockClient) {
        this.stockClient = stockClient;
    }

    @GetMapping("/order/create")
    public String createOrder(@RequestParam(value = "productId",required = false,defaultValue = "999")String productId,
                              @RequestParam(value = "stockNum",required = false,defaultValue = "3")Integer stockNum) {
        log.info("创建订单, 商品ID: {}, 数量: {}", productId, stockNum);
        String stockResult = stockClient.reduceStock(productId, stockNum);
        return "订单创建成功, 调用库存服务结果: " + stockResult;
    }
}
